TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file AxisLabels.php

Documentation is available at AxisLabels.php

  1. <?php
  2.  
  3.  /**
  4.  * AxisLabels class
  5.  *
  6.  * Description: Axis Label characteristics
  7.  *
  8.  * @author
  9.  * @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  10.  * @version 1.0
  11.  * @package TeeChartPHP
  12.  * @subpackage axis
  13.  * @link http://www.steema.com
  14.  */
  15.  
  16.  class AxisLabels extends TextShape {
  17.  
  18.     // Private Properties
  19.     private $align;
  20.     private $customSize=0;
  21.     private $multiline=false;
  22.     private $exactDateTime = true;
  23.     private $roundfirstlabel = true;
  24.     private $items;
  25.     private $labelsAlternate=false;
  26.  
  27.     // Protected Properties
  28.     protected $iAngle=0;
  29.     protected $iSeparation = 10;
  30.     protected $bExponent;
  31.     protected $axisvaluesformat; // = "DefValueFormat"; // $Language.getString("DefValueFormat");
  32.     protected $valuesDecimal=2;
  33.     protected $sDatetimeformat = "";
  34.     protected $bOnAxis = true;
  35.  
  36.     // Public Properties
  37.     public $iStyle;
  38.     public $position;    // protected before
  39.     public $axis;        // protected before
  40.  
  41.     private static $LOCALE;
  42.  
  43.     // Interceptors
  44.     function __get( $property ) {
  45.       $method ="get{$property}";
  46.       if ( method_exists( $this, $method ) ) {
  47.         return $this->$method();
  48.       }
  49.     }
  50.  
  51.     function __set ( $property,$value ) {
  52.       $method ="set{$property}";
  53.       if ( method_exists( $this, $method ) ) {
  54.         return $this->$method($value);
  55.       }
  56.     }
  57.  
  58.     /**
  59.      * Accesses the Label characteristics of Axis Labels.
  60.      *
  61.      * @param a Axis
  62.      */
  63.     public function AxisLabels($a) {
  64.  
  65.         $this->iStyle = AxisLabelStyle::$AUTO;
  66.         $this->align= AxisLabelAlign::$DEF;
  67.         $this->axisvaluesformat = Language::getString("DefValueFormat");
  68.  
  69.         // Set Locale
  70.         setlocale(LC_ALL,'');
  71.         self::$LOCALE = localeconv();
  72.  
  73.         parent::TextShape($a->chart);
  74.        
  75.         $this->axis = $a;
  76.         $this->bTransparent = true;
  77.         $this->items = new AxisLabelsItems($a);
  78. //        $this->readResolve();
  79.     }
  80.  
  81.     protected function readResolve() {
  82. /*
  83.         $locale = localeconv();
  84.         $this->valuesDecimal = $locale['decimal_point'];
  85. // todo         $this->valuesDecimal = new NumberFormat(); // TODO $this->Language->getString("DefValueFormat"));
  86.         return $this;
  87. */
  88.     }
  89.  
  90.     protected function shouldSerializeTransparent() {
  91.         return!$this->bTransparent;
  92.     }
  93.  
  94.         /**
  95.           * Determines whether Axis.Increment calculates Axis Labels in
  96.           * exact DateTime steps. <br>
  97.           * This is very useful when Axis.Increment is a DateTimeStep constant value.
  98.           * <br>When ExactDateTime is false (the default value), the OneMonth
  99.           * increment equals 30 days, and axis do not calculate how many days a
  100.           * month has. <br>
  101.           * The Series XValues or YValues properties should have DateTime = true.
  102.           * ( XValues for horizontal Axis and YValues for vertical Axis).
  103.           *
  104.           * Default value: false
  105.           *
  106.           * @return boolean 
  107.           */
  108.     public function getExactDateTime() {
  109.         return $this->exactDateTime;
  110.     }
  111.  
  112.         /**
  113.           * Determines whether Axis.Increment calculates Axis Labels in
  114.           * exact DateTime steps. <br>
  115.           * Default value: false
  116.           *
  117.           * @param value boolean
  118.           */
  119.     public function setExactDateTime($value) {
  120.         $this->exactDateTime = $this->setBooleanProperty($this->exactDateTime, $value);
  121.     }
  122.  
  123.         /**
  124.           * Defines the rotation degree applied to each Axis Label. Valid angle
  125.           * in degrees are 0, 90, 180, 270 and 360. <br>
  126.           * Please note that some printers and video drivers fail when drawing
  127.           * rotated fonts or calculating the rotated font dimensions.
  128.           * Metafile Charts containing rotated fonts sometimes place text
  129.           * at sligthly different coordinates.
  130.           *
  131.           * Default value: 0
  132.           *
  133.           * @return int 
  134.           */
  135.     public function getAngle() {
  136.         return $this->iAngle;
  137.     }
  138.         /**
  139.           * Defines the rotation degree applied to each Axis Label.<br>
  140.           * Default value: 0
  141.           *
  142.           * @param value int
  143.           */
  144.     public function setAngle($value) {
  145.         $this->iAngle = $this->setIntegerProperty($this->iAngle, $value % 360);
  146.     }
  147.  
  148.         /**
  149.           *
  150.           * Determines whether the Labels at Axis Minimum and Maximum positions
  151.           * will be shown or not.<br>
  152.           *
  153.           * Default value: true
  154.           *
  155.           * @return boolean 
  156.           */
  157.     public function getOnAxis() {
  158.         return $this->bOnAxis;
  159.     }
  160.         /**
  161.           * Shows the Labels at Axis Minimum and Maximum positions when true.<br>
  162.           * Default value: true
  163.           *
  164.           * @param value boolean
  165.           */
  166.     public function setOnAxis($value) {
  167.         $this->bOnAxis = $this->setBooleanProperty($this->bOnAxis, $value);
  168.     }
  169.  
  170.         /**
  171.           * Specifies the minimum distance between Axis Labels as a percentage.
  172.           * Setting it to "0" zero makes Axis skip calculating overlapping labels.
  173.           * (No clipping is performed). Labels visibility depends also on
  174.           * Labels.Font size, Labels.Angle and Axis.Increment properties. <br>
  175.           * Default value: 10
  176.           *
  177.           * @return int 
  178.           */
  179.     public function getSeparation() {
  180.         return $this->iSeparation;
  181.     }
  182.  
  183.         /**
  184.           * Specifies the minimum distance between Axis Labels as a percentage.<br>
  185.           * Default value: 10
  186.           *
  187.           * @param value int
  188.           */
  189.     public function setSeparation($value) {
  190.         $this->iSeparation = $this->setIntegerProperty($this->iSeparation, $value);
  191.     }
  192.  
  193.         /**
  194.           * Changes the spacing occupied by the axis labels between the Ticks and
  195.           * the Title.<br>
  196.           * Default value: 0
  197.           *
  198.           * @return int 
  199.           */
  200.     public function getCustomSize() {
  201.         return $this->customSize;
  202.     }
  203.  
  204.         /**
  205.           * Changes the spacing occupied by the axis labels between the Ticks and
  206.           * the Title.<br>
  207.           * Default value: 0
  208.           *
  209.           * @param value int
  210.           */
  211.     public function setCustomSize($value) {
  212.         $this->customSize = $this->setIntegerProperty($this->customSize, $value);
  213.     }
  214.  
  215.         /**
  216.           * The style of the labels. Setting Axis.Label.Style to talAuto will
  217.           * force the Axis to guess what labels will be drawn. For each Active
  218.           * associated Series, if the Series have XLabels then the Label.Style
  219.           * will be talText. If no Series have XLabels, then Label.Style will be
  220.           * talValue. If no Active Series are associated with the Axis,
  221.           * then Label.Style will be talNone. <br>
  222.           * Default value: AxisLabelStyle.Auto
  223.           *
  224.           * @return AxisLabelStyle 
  225.           */
  226.     public function getStyle() {
  227.         return $this->iStyle;
  228.     }
  229.  
  230.         /**
  231.           * Sets the style of the labels.<br>
  232.           * Default value: AxisLabelStyle.Auto
  233.           *
  234.           * @param value AxisLabelStyle
  235.           */
  236.     public function setStyle($value) {
  237.         if ($this->iStyle != $value) {
  238.             $this->iStyle = $value;
  239.             $this->invalidate();
  240.         }
  241.     }
  242.  
  243.         /**
  244.           * Controls if Axis labels will be automatically "rounded" to the nearest
  245.           * magnitude. Run-time only. This applies both to DateTime and non-DateTime
  246.           * axis values. When false, Axis labels will start at Maximum Axis value.<br>
  247.           * Default value: true
  248.           *
  249.           * @return boolean 
  250.           */
  251.     public function getRoundFirstLabel() {
  252.         return $this->roundfirstlabel;
  253.     }
  254.  
  255.         /**
  256.           * Axis labels will be automatically "rounded" to the nearest magnitude when
  257.           * true.<br>
  258.           * Default value: true
  259.           *
  260.           * @param value boolean
  261.           */
  262.     public function setRoundFirstLabel($value) {
  263.         $this->roundfirstlabel = $this->setBooleanProperty($this->roundfirstlabel, $value);
  264.     }
  265.  
  266.         /**
  267.           * Standard DateTime formatting string specifier used to draw the
  268.           * axis labels.<br>
  269.           * Default value: ""
  270.           *
  271.           * @return String 
  272.           */
  273.     public function getDateTimeFormat() {
  274.         return $this->sDatetimeformat;
  275.     }
  276.  
  277.         /**
  278.           * Standard DateTime formatting string specifier used to draw the
  279.           * axis labels.<br>
  280.           * Default value: ""
  281.           *
  282.           * @param value String
  283.           */
  284.     public function setDateTimeFormat($value) {
  285.         $this->sDatetimeformat = $this->setStringProperty($this->sDatetimeformat, $value);
  286.     }
  287.  
  288.         /**
  289.           * Specifies the desired formatting string to be applied to Axis Labels.
  290.           * It has effect when Axis associated Series have their XValues.DateTime
  291.           * or YValues.DateTime property set to false.<br>
  292.           * For DateTime Axis labels use the AxisLabels.DateTimeFormat property.<br>
  293.           * ValueFormat is a standard formatting string specifier. Chart Axis uses
  294.           * it to draw the axis labels. Chart Series uses it to draw the Marks. <br>
  295.           * Default value: '#,##0.###'
  296.           *
  297.           * @return formatting String to be applied to Axis Labels.
  298.           */
  299.     public function getValueFormat() {
  300.         return $this->axisvaluesformat;
  301.     }
  302.  
  303.         /**
  304.           * Specifies the desired formatting string to be applied to Axis Labels.<br>
  305.           * Default value: '#,##0.###'
  306.           *
  307.           * @param value String
  308.           */
  309.     public function setValueFormat($value) {
  310.       if ($this->axisvaluesformat != $value) {
  311.         $this->axisvaluesformat = $this->setStringProperty($this->axisvaluesformat, $value);
  312.         // todo $this->valuesDecimal = new NumberFormat($this->axisvaluesformat);
  313.       }
  314.     }
  315.  
  316.         /**
  317.           * Automatically breaks DateTime Labels on occurence of a space " ".
  318.           * Use '\n' in other label types to break a line or use SplitInLines in
  319.           * the OnGetAxisLabel event. <br>
  320.           * Default value: false
  321.           *
  322.           * @return boolean 
  323.           */
  324.     public function getMultiLine() {
  325.         return $this->multiline;
  326.     }
  327.  
  328.         /**
  329.           * Automatically breaks DateTime Labels on occurence of a space " ".<br>
  330.           * Default value: false
  331.           *
  332.           * @param value boolean
  333.           */
  334.     public function setMultiLine($value) {
  335.         $this->multiline = $this->setBooleanProperty($this->multiline, $value);
  336.     }
  337.  
  338.         /**
  339.           * Sets Separator String to invoke 'new line' in String St. Replaces input
  340.           * string St with separator to be used to break lines at each occurrence
  341.           * of the separator.
  342.           *
  343.           * @param s Input String
  344.           * @param separator String to be used for new line
  345.           * @return String 
  346.           */
  347.     public function splitInLines($s, $separator) {
  348.          $loc = 0;
  349.  
  350.         do {
  351.             $loc = $s->indexOf($separator, 0);
  352.             if ($loc > 0) {
  353.                 $s = $s->substring(0, $loc - 1) + Language::getString("LineSeparator");
  354.             }
  355.         } while ($loc != -1);
  356.  
  357.         return $s;
  358.     }
  359.  
  360.         /**
  361.           * Enables/disables the display of Axis Labels in exponent format with
  362.           * super-script fonts.<br>
  363.           * Default value: false
  364.           *
  365.           * @return boolean 
  366.           */
  367.     public function getExponent() {
  368.         return $this->bExponent;
  369.     }
  370.  
  371.         /**
  372.           * Enables/disables the display of Axis Labels in exponent format with
  373.           * super-script fonts.<br>
  374.           * Default value: false
  375.           *
  376.           * @param value boolean
  377.           */
  378.     public function setExponent($value) {
  379.         $this->bExponent = $this->setBooleanProperty($this->bExponent, $value);
  380.     }
  381.  
  382.         /**
  383.           * The position of Labels on an Axis.<br>
  384.           * The default position of an AxisLabel will depend on the Axis with which
  385.           * it is associated. A Bottom Axis will place Labels below the Axis by
  386.           * default. A Top Axis will place the Labels above the Axis.<br>
  387.           * Default value: Default position <br>
  388.           * Opposite: Labels positioned on the opposite side to the default position.
  389.           *
  390.           * @return AxisLabelAlign 
  391.           */
  392.     public function getAlign() {
  393.         return $this->align;
  394.     }
  395.  
  396.         /**
  397.           * Sets the position of Labels on an Axis.<br>
  398.           * Default value: Default position
  399.           *
  400.           * @param value AxisLabelAlign
  401.           */
  402.     public function setAlign($value) {
  403.         if ($this->align != $value) {
  404.             $this->align = $value;
  405.             $this->invalidate();
  406.         }
  407.     }
  408.  
  409.         /**
  410.           * Contains the custom labels.
  411.           *
  412.           * @return AxisLabelsItems 
  413.           */
  414.     public function getItems() {
  415.         return $this->items;
  416.     }
  417.  
  418.     private function internalLabelSize($value, $isWidth) {
  419.          $m = $this->chart->multiLineTextWidth($this->labelValue($value));
  420.  
  421.          $result = $m->width;
  422.          $tmp = $m->count;
  423.  
  424.         if ($isWidth) {
  425.             $tmpMulti = ($this->iAngle == 90) || ($this->iAngle == 270);
  426.         } else {
  427.             $tmpMulti = ($this->iAngle == 0) || ($this->iAngle == 180);
  428.         }
  429.  
  430.         if ($tmpMulti) {
  431.             $result = $this->chart->getGraphics3D()->getFontHeight() * $tmp;
  432.         }
  433.  
  434.         return $result;
  435.     }
  436.  
  437.         /**
  438.           * returns the Axis Label width of the Value parameter. It uses the Axis
  439.           * formatting specifiers, the Axis Labels Font and the Labels rotation
  440.           * and style.
  441.           *
  442.           * @param value double Axis value
  443.           * @return int Axis Label width in pixels
  444.           */
  445.     public function labelWidth($value) {
  446.         //            int tmp;
  447.         //            int tmpResult=chart.MultiLineTextWidth(LabelValue(value),tmp);
  448.         //            if ((angle==90) || (angle==270))
  449.         //            {
  450.         //                tmpResult=chart.getGraphics3D().FontHeight*tmp;
  451.         //            }
  452.         return $this->internalLabelSize($value, true);
  453.         //return tmpResult;
  454.     }
  455.  
  456.         /**
  457.           * returns the Axis Label height of the Value parameter. It uses the Axis
  458.           * formatting specifiers, the Axis Labels Font and the Labels rotation
  459.           * and style.
  460.           *
  461.           * @param value double Axis value
  462.           * @return int Axis Label height in pixels
  463.           */
  464.     public function labelHeight($value) {
  465.         return $this->internalLabelSize($value, false);
  466.         //            int tmp;
  467.         //            int tmpResult=chart.MultiLineTextWidth(LabelValue(value),out tmp);
  468.         //            if ((angle==0) || (angle==180))
  469.         //                tmpResult=chart.getGraphics3D().FontHeight*tmp;
  470.         //            return tmpResult;
  471.     }
  472.  
  473.     /**
  474.     * returns the corresponding text representation of the Value parameter.
  475.     * It uses the Axis formatting specifiers.
  476.     *
  477.     * @param value double
  478.     * @return String 
  479.     */
  480.     public $labelText = '';
  481.     
  482.     public function labelValue($value) {
  483.  
  484.         if ($this->axis->iAxisDateTime) {
  485.      //MM todo   //if ((value >= -657435) && (value <= 2958466)){
  486.                 try {  //CDI TF02010053
  487.                     if (strlen($this->sDatetimeformat) == 0) {
  488.                         $tmpResult = date($this->axis->dateTimeDefaultFormat($this->axis->iRange),$value);
  489.                     } else {
  490.                         $tmpResult = date($this->sDatetimeformat,$value);
  491.                     }
  492.                 } catch (Exception $e) {
  493.                         $tmpResult = date($this->axis->dateTimeDefaultFormat($this->axis->iRange),$value);
  494.                 }
  495.        /* } else {
  496.             $tmpResult="";
  497.           }  */
  498.         } else {
  499.             try { // CDI TF02010053
  500.                 //setlocale(LC_ALL,'');
  501.                 //$locale = localeconv();
  502.  
  503.                 if (fmod((double)$value,1)!=0) {
  504.                   if (self::$LOCALE['frac_digits'] != $this->valuesDecimal)
  505.                     $decimals=$this->valuesDecimal;
  506.                   else
  507.                     $decimals=self::$LOCALE['frac_digits'];
  508.                 }
  509.                 else
  510.                   $decimals=0;
  511.  
  512.                 $tmpResult = number_format($value,$decimals,
  513.                     self::$LOCALE['decimal_point'],
  514.                     self::$LOCALE['thousands_sep']);
  515.  
  516.                 if ($tmpResult=='-0') {
  517.                     $tmpResult='0';
  518.                 }
  519.  
  520.             } catch (Exception $e) {
  521.                 $locale = localeconv();
  522.                 $tmpResult = number_format($value, $decimals,
  523.                     $locale['decimal_point'],
  524.                     $locale['thousands_sep']);
  525.             }
  526.         }
  527.  
  528.         $parent=$this->chart->getParent();
  529.         
  530.         if ($parent != null) {
  531.             $this->labelText = $tmpResult;
  532.             // Args  : Axis, valueindex display order, label
  533.             $parent->TriggerEvent('OnGetAxisLabel', array($this->axis,$this->axis->labelIndex, $this->labelText));
  534.             
  535.             if ($this->labelText != $tmpResult)
  536.                $tmpResult = $this->labelText;
  537.         }
  538.  
  539.         if ($this->multiline) {
  540.             $tmpResult = $this->splitInLines($tmpResult, " ");
  541.         }
  542.  
  543.         return $tmpResult;
  544.     }
  545.  
  546.     public function setFrac_digits($value) {
  547.         $this->valuesDecimal = $this->setIntegerProperty($this->valuesDecimal, $value);
  548.     }
  549.  
  550.     public function getFrac_digits() {
  551.         return $this->valuesDecimal;
  552.     }
  553.  
  554.     /**
  555.      * Gets the axis labels to be drawn in two rows or columns.
  556.      *
  557.      * @return boolean 
  558.      */
  559.     public function getAlternate() {
  560.         return $this->labelsAlternate;
  561.     }
  562.  
  563.     /**
  564.      * Gets the axis labels to be drawn in two rows or columns.
  565.      *
  566.      * @return boolean 
  567.      */
  568.     public function setAlternate($value) {
  569.         $this->labelsAlternate=$this->setBooleanProperty($this->labelsAlternate,$value);
  570.     }
  571.  
  572. }
  573.  
  574. ?>

Documentation generated on Wed, 16 Jun 2010 12:03:14 +0200 by phpDocumentor 1.4.1